<?php

namespace addons\booking\controller;

use addons\booking\model\Store as StoreModel;
use addons\booking\model\Worker as WorkerModel;
use addons\booking\model\StoreOrderSon;
use addons\booking\model\StoreShield;
use think\Db;
use think\Session;


class Worker extends Base
{
    protected $noNeedLogin = [];
    protected $modelValidate = true; //是否开启Validate验证，默认是false关闭状态
    protected $modelSceneValidate = true; //是否开启模型场景验证，默认是false关闭状态



    //抢单大厅
    public function order_hall()
    {
        $worker_id = $this->request->param('worker_id/d',0);
        $latitude = $this->request->param('latitude','');
        $longitude = $this->request->param('longitude','');
        $page = $this->request->param('page/d',1);
        $limit = $this->request->param('limit/d',10);
        $where['order_date'] = $this->request->param('order_date',0);
        $where['time_key'] = $this->request->param('time_key',0);
        $where['start_distance'] = $this->request->param('start_distance',0);
        $where['end_distance'] = $this->request->param('end_distance',0);
        $where['store_id'] = $this->request->param('store_id',0);

        if(!$latitude || !$longitude){
            $this->error('参数错误');
        }

        $list = StoreOrderSon::order_hall($worker_id,$page,$limit,$latitude,$longitude,$where);
        $this->success('',$list);
    }

    //更新保洁信息
    public function update_worker(){
        $worker_id = $this->request->param('worker_id/d',0);
        $latitude = $this->request->param('latitude','');
        $longitude = $this->request->param('longitude','');
        $address = $this->request->param('address','');
        if(!$worker_id)   $this->error('参数错误');
        $data = [];
        if($latitude) $data['latitude'] = $latitude;
        if($longitude) $data['longitude'] = $longitude;
        if($address) $data['address'] = $address;


        if(!$data)   $this->error('没有修改内容');
        $data['updatetime'] = time();
        $res = WorkerModel::where('id',$worker_id)->update($data);
        if($res){
            $this->success('修改成功');
        } else {
            $this->error('修改失败');
        }
    }
}
